<template>
    <a-input-password v-model:value="OldPassword" placeholder="原始密码">
        <template #prefix>
            <lock-outlined class="icon" type="user" />
            &nbsp;&nbsp;
        </template>
    </a-input-password>
    <br><br>
    <a-input-password v-model:value="NewPassword" placeholder="新密码">
        <template #prefix>
            <lock-outlined class="icon" type="user" />
            &nbsp;&nbsp;
        </template>
    </a-input-password>
    <br><br>
    <a-input-password v-model:value="AgainPassword" placeholder="确认新密码">
        <template #prefix>
            <lock-outlined class="icon" type="user" />
            &nbsp;&nbsp;
        </template>
    </a-input-password>
</template>
<script lang="ts" setup>
import { LockOutlined } from '@ant-design/icons-vue';
import { notification } from 'ant-design-vue'
import { ref } from 'vue';
import apis from '@/apis/user'

const OldPassword = ref<String>('');
const NewPassword = ref<String>('');
const AgainPassword = ref<String>('');

const emit = defineEmits(['LogOut', 'ClearLoading']);

const ResetPassword = () => {
    if (!OldPassword.value) {
        notification.error({ message: '原密码不能为空' });
        emit('ClearLoading')
        return;
    };
    if (!NewPassword.value) {
        notification.error({ message: '新密码不能为空' });
        emit('ClearLoading')
        return;
    };
    if (!AgainPassword.value) {
        notification.error({ message: '确认密码不能为空' });
        emit('ClearLoading')
        return;
    };
    if (OldPassword.value == NewPassword.value) {
        notification.error({ message: '新密码与旧密码一致' });
        emit('ClearLoading')
        return;
    };
    if (AgainPassword.value != NewPassword.value) {
        notification.error({ message: '两次输入新密码不一致' });
        emit('ClearLoading')
        return;
    };
    apis.Repassword({
        OldPassword: OldPassword.value,
        password: NewPassword.value
    }).then((res: any) => {
        emit('LogOut');
    });
}

defineExpose({
    ResetPassword,
})

</script>
<style lang="less" scoped>

</style>